package dungeons;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import squares.Direction;
import squares.IllegalSquareException;
import squares.IllegalTemperatureTypeException;
import squares.InvalidHumidityException;
import squares.InvalidTemperatureException;
import squares.RockSquare;
import squares.Square;
import squares.TransparentSquare;
import squares.Square.TemperatureType;

public class PlateauTest {

	private static Square square1,square2,square4,square5,square6,square7,square11,square12,squareExceptionHeatDamage;
	private static Plateau<Square> dungeon;
	private static RockSquare rock1,rock2,rock3;
	private static TransparentSquare transparentSquare1,transparentSquare2;


	
	@Before
	public void setUp() throws Exception {
		square1 = new Square(100,TemperatureType.CELSIUS, 50, false, false);
		square2 = new Square(100,TemperatureType.CELSIUS,50,false, true);
		square4 = new Square(100,TemperatureType.CELSIUS,50,false, true);
		square5 = new Square(100,TemperatureType.CELSIUS,50,false, false);
		square6 = new Square(100,TemperatureType.CELSIUS,50,false, false);
		square7 = new Square(100,TemperatureType.CELSIUS,50,false, true);
		square11 = new Square(100,TemperatureType.CELSIUS,50,false, true);

		square12 = new Square(100,TemperatureType.CELSIUS,50,false, true);
		square2.addTeleportableSquare(square4);
		square11.addTeleportableSquare(square2);
		square7.addTeleportableSquare(square2);
		square7.addTeleportableSquare(square11);
		square4.addTeleportableSquare(square7);
		dungeon = new Plateau<Square>(Long.MAX_VALUE,Long.MAX_VALUE);
		
		
		rock1 = new RockSquare();
		rock2 = new RockSquare();
		rock3 = new RockSquare();
		
		
		Square.setMinTemperature(-200, TemperatureType.CELSIUS);
		Square.setMaxTemperature(5000,TemperatureType.CELSIUS);
		squareExceptionHeatDamage = new Square(1000,TemperatureType.CELSIUS,14,false, false);

		transparentSquare1 = new TransparentSquare(1500,TemperatureType.CELSIUS,50,false,false,Direction.WEST, false);
		transparentSquare2 = new TransparentSquare(1000,TemperatureType.CELSIUS,40,false,false,Direction.NORTH, false);
		
		
		dungeon.addSquare(rock3, 54, 54, 0);
		dungeon.addSquare(rock1, 54, 53, 0);
		dungeon.addSquare(rock2, 53, 54, 0);
		}
	
	@Test
	public void testAddSquare() throws IllegalArgumentException, IllegalSquareException {
		dungeon.addSquare(square5, 1, 2, 0);
		assertEquals(square5,dungeon.getSquareAt(1, 2, 0));
		dungeon.addSquare(square1, 10, 20, 0);
		dungeon.addSquare(squareExceptionHeatDamage, 11, 20, 0);
		dungeon.addSquare(transparentSquare1, 10, 21, 0);
		dungeon.addSquare(square4, 12, 20, 0);
		dungeon.addSquare(square6, 13, 20, 0);
		dungeon.addSquare(square7, 12, 21, 0);
		dungeon.addSquare(transparentSquare2, 10, 25, 0);

		}
	@Test (expected = IllegalSquareException.class)
	public void testAddSquare_IllegalCase() throws IllegalSquareException
	{
		//reeds in dungeon
		dungeon.addSquare(square1, 1, 1, 0);
		dungeon.addSquare(square1, 32, 12, 0);
	}
	@Test (expected = IllegalArgumentException.class)
	public void testAddSquare_IllegalCase2() throws IllegalArgumentException, IllegalSquareException
	{
		//buiten maxvalue
		dungeon.addSquare(square12, 1, 1, 4);
	}

	@Test
	public void testWillHaveValidBorders() throws IllegalArgumentException, IllegalSquareException {
		
		dungeon.addSquare(square5, 1, 2, 0);
		assertEquals(square5,dungeon.getSquareAt(1, 2, 0));
		dungeon.addSquare(square1, 10, 20, 0);
		
		dungeon.addSquare(squareExceptionHeatDamage, 11, 20, 0);
		dungeon.addSquare(transparentSquare1, 10, 21, 0);
		dungeon.addSquare(square4, 12, 20, 0);
		dungeon.addSquare(square6, 13, 20, 0);
		dungeon.addSquare(square7, 12, 21, 0);


	}
	
	@Test 
	public void testWillHaveValidBorders_IllegalCase() throws IllegalArgumentException, IllegalSquareException, InvalidTemperatureException, InvalidHumidityException, IllegalTemperatureTypeException
	{
		Square square = new Square(200,TemperatureType.CELSIUS,40,false,false);
		dungeon.addSquare(square, 11, 21, 0);
		
		assert(!dungeon.willHaveValidBorders(transparentSquare1, 10, 21, 0));
	}


}
